﻿using System;
using Habanero.Base;
using Habanero.BO;
using UseCaseManager.BO;

namespace UseCaseManager.Logic
{
    public class UseCaseManagerRegistry
    {
        private static Project _currentProject;
        //private static BusinessObjectCollection<Drop> _drops;

        public static Project CurrentProject
        { 
            get
            {
                BusinessObjectCollection<Project> projectsCol = Broker.GetBusinessObjectCollection<Project>("", "");
                //TODO: Which exception type is appropriate?
                if(projectsCol.Count==0)
                {
                    throw (new Exception("No project has been loaded."));
                }
                if (projectsCol.Count > 1)
                {
                    throw (new NotSupportedException(
                        "Use Case Manager does not currently support more than 1 project in the database."));
                }
                _currentProject = Broker.GetBusinessObjectCollection<Project>("", "")[0];
                return _currentProject;
            }
            //set
            //{
            //    _currentProject = value;
            //}
        }

        public static BusinessObjectCollection<Drop> Drops
        {
            get
            {
                //no projectID property on Drop object: so drop in release in project
                //Criteria criteriaRelease=new Criteria("ProjectID", Criteria.ComparisonOp.Equals, _currentProject.ProjectID);
                //Criteria criteriaDrop= new Criteria("ReleaseID", Criteria.);
                BusinessObjectCollection<Drop> dropsCol = Broker.GetBusinessObjectCollection<Drop>("","EndDate");
                return dropsCol;
            }
        }
    }
}
